package machine;

import data.MachineStatus;

abstract class BaseAgriculturalMachine implements AgriculturalMachine {
    protected final String machineId;
    protected final MachineStatus status;
    protected final String type;

    public BaseAgriculturalMachine(String type, String id) {
        this.type = type;
        this.machineId = id;
        this.status = new MachineStatus();
    }

    @Override
    public String getMachineId() {
        return machineId;
    }

    @Override
    public String getType() {
        return type;
    }

    @Override
    public String getMachineInfo() {
        return type + " | 编号: " + machineId;
    }

    @Override
    public MachineStatus getStatus() {
        // 每次获取状态时更新（模拟实时监控）
        status.updateRandomStatus();
        return status;
    }

    @Override
    public void assignTask(String task) {
        status.assignTask(task);
    }
    @Override
    public void start() {
        System.out.println(machineId + ": 启动引擎");
        status.setState("工作中");
    }

    @Override
    public void stop() {
        System.out.println(machineId + ": 关闭引擎");
        status.setState("空闲");
    }

    @Override
    public void moveTo(String position) {
        System.out.println(machineId + ": 移动到 " + position);
        status.setPosition(position);
    }

    @Override
    public void operateAttachment(String operation) {
        System.out.println(machineId + ": 执行附件操作 - " + operation);
        status.setCurrentTask(operation);
    }

    @Override
    public void stopAttachment() {
        System.out.println(machineId + ": 停止附件操作");
        status.setCurrentTask("无");
    }
}